package com.yfeng.goodjuhome.model;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.yfeng.common.dao.IDao;
import com.yfeng.common.dao.Param;

@Component
public class Permission {

	private String id; // 用户id
	private String name; 
	private String link; 

	@Autowired
	public  IDao baseDao;

	public Permission() {
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	@Override
	public String toString() {
		return "adminid:" + id + ",name:" + name + ",link:" + link;
	}

	public  Permission getPermissionById(String id) throws Exception {
		Permission permission=new Permission();
		List list = baseDao.query("select t1.* from permissions t1 where t1.id=:id",new Param("id", id));
		Map userRow = (Map) list.get(0);
		permission.setId(id);
		permission.setName(userRow.get("name").toString());
		permission.setLink(userRow.get("link").toString());
		return permission;
	}

	public  boolean isExist(String name) throws Exception {

		int ret = baseDao.getRowCount("from permissions where name=:name", new Param("name", name));
		if (ret > 0)
			return true;
		else
			return false;

	}
	public  boolean isExist(int link) throws Exception {

		int ret = baseDao.getRowCount("from permissions where link=:link", new Param("link", link));
		if (ret > 0)
			return true;
		else
			return false;

	}
}
